<?php

namespace App;

use App\model\panyuan\UserShenheLog;
use App\model\Workshop;
use Illuminate\Database\Eloquent\Model;

/**
 * App\UserShenhe
 *
 * @property int $id
 * @property int|null $user_id
 * @property string|null $title
 * @property string|null $desc
 * @property int|null $type 0 审核创建房源 1审核更新房源 2 审核业主信息
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null $button
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereButton($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereUserId($value)
 * @mixin \Eloquent
 * @property int|null $workshop_id
 * @property int|null $role_id 管理员审核
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereRoleId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereWorkshopId($value)
 * @property int|null $is_read 是否已读
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereIsRead($value)
 * @property string|null $code 编号
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereCode($value)
 * @property string|null $status 0 审核中 1统一 2 拒绝
 * @property string|null $refuseReason
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereRefuseReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserShenhe whereStatus($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\panyuan\UserShenheLog[] $log
 * @property-read int|null $log_count
 * @property-read \App\User|null $user
 * @property-read \App\model\Workshop|null $workshop
 * @property-read \App\model\admin\Workshop|null $adminWorkshop
 */
class UserShenhe extends Model
{

    const Created_panyuan=0;
    const Updated_panyuan=1;
    const View_panyuan=2;
    public static $typeMap=[
            self::Created_panyuan=>'创建盘源审核',
            self::Updated_panyuan=>'修改盘源审核',
            self::View_panyuan=>'申请查看业主信息'
    ];
    const STATUS_SHENHE=0;
    const STATUS_TONGYI=1;
    const STATUS_JUJUE=2;
    const STATUS_CANLE=3;
    public static $statusMap=[
        self::STATUS_SHENHE=>'审核中',
        self::STATUS_JUJUE=>'拒绝',
        self::STATUS_TONGYI=>'同意',
        self::STATUS_CANLE=>'已取消'
    ];

    protected $table='user_shenhe';
    public function log(){
       return $this->hasMany(UserShenheLog::class,'code','code');
    }
    public function user(){
        return $this->belongsTo(User::class,'user_id');
    }
    public function workshop(){
        return $this->belongsTo(Workshop::class,'workshop_id');
    }
    public function adminWorkshop(){
        return $this->belongsTo(\App\model\admin\Workshop::class,'workshop_id');
    }
}
